package com.zzyl.nursing.controller.member;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.DevicePropertyDto;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;
    @Autowired
    private IDeviceDataService deviceDataService;
    @Autowired
    private IDeviceService deviceService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }


    @PostMapping("/add")
    @ApiOperation("绑定老人")
    public AjaxResult add(@RequestBody MemberElderDto dto){
        familyMemberService.add(dto);
        return AjaxResult.success();
    }

    @GetMapping("/my")
    @ApiOperation("查询我的老人")
    public AjaxResult my(){
        return AjaxResult.success(familyMemberElderService.my());
    }

    @GetMapping("/list-by-page")
    @ApiOperation("看家人列表 (分页查询)")
    public AjaxResult listByPage(Integer pageNum, Integer pageSize){

        return AjaxResult.success(familyMemberElderService.listByPage(pageNum, pageSize));
    }
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("健康数据查询")
    public AjaxResult queryDevicePropertyStatus(@PathVariable String iotId){
        return AjaxResult.success(deviceDataService.queryServiceProperties(iotId));
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("健康数据查询")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody DevicePropertyDto dto){
        return AjaxResult.success(deviceDataService.QueryDevicePropertyStatus(dto));
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("查询每日健康数据")
    public AjaxResult queryDeviceDataListByDay(String functionId, Long startTime, Long endTime, String iotId){
        return AjaxResult.success(deviceDataService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId));
    }
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("查询每日健康数据")
    public AjaxResult queryDeviceDataListByWeek(String functionId, Long startTime, Long endTime, String iotId){
        return AjaxResult.success(deviceDataService.queryDeviceDataListByWeek(functionId, startTime, endTime, iotId));
    }


}
